<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="./js/jquery.js"></script>
    <style>
        .box{
            width: 200px;
            height: 200px;
            background: skyblue;
            position: absolute;
        }
    </style>
</head>
<body>
    <div class="box"></div>
    <script>
        $.fn.extend({
            dragBox(){
                let self=this
                this.on("mousedown",(e)=>{
                    var disX=e.pageX-this.offset().left;
                    var disY=e.pageY-this.offset().top;
                    $(document).on("mousemove",function(e){
                        self.css({
                            left:e.pageX-disX,
                            top:e.pageY-disY
                        })
                    })
                    $(document).on("mouseup",function(){
                        $(document).off("mousemove mouseup")
                    })
                })
            }
        })

        $(function(){
            $(".box").dragBox()
        })
    </script>
</body>
</html>